package com.tangqiao;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.sql.Date;
import java.util.Calendar;

public class TimeGetter {
	public static String getTime() {
		String ret = null;
		String postinfo = "username=0711050138&password=7ccBDccB%3acc67cc%40&drop=0&type=2&n=11&mac=%3cdc7Bcc%3f%3bcc%419cc%3dBcc%3bDcc5Ccc%3eAcd%3a7c";
		try {
			Socket s = new Socket(InetAddress.getByName("172.16.202.201"), 3333);
			InputStream ins = s.getInputStream();
			OutputStream ous = s.getOutputStream();
			String sj;
			sj = "POST /cgi-bin/do_login HTTP/1.1" + "\r\n"
					+ "Content-Type: application/x-www-form-urlencoded"
					+ "\r\n" + "User-Agent: my session" + "\r\n"
					+ "Host: 172.16.202.201:3333" + "\r\n";
			sj += "Content-Length: " + postinfo.length() + "\r\n";
			sj += "Cache-Control: no-cache" + "\r\n";
			sj += "" + "\r\n";

			sj += postinfo;
			byte[] b1 = sj.getBytes();
			ous.write(b1);

			BufferedReader br = new BufferedReader(new InputStreamReader(ins));
			while (true) {
				String line = br.readLine();
				if (line == null)
					break;
				if (line.startsWith("password_error"))  // like :password_error@1264693824
					ret = line;
			}
			br.close();
			ous.close();
			s.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		ret = "" + Integer.parseInt(ret.substring(ret.indexOf('@')+1)) / 60;
		return ret; 
	}
	public static void main(String[] args) {
		Calendar date = Calendar.getInstance();
		System.out.println(date.get(Calendar.YEAR)+"-"+(date.get(Calendar.MONTH)+1) +"-"+ date.get(Calendar.DATE) + " "+ date.get(Calendar.HOUR_OF_DAY)+ ":" + date.get(Calendar.MINUTE)+":"+ date.get(Calendar.SECOND) );
//		System.out.println(TimeGetter.getTime());
	}
}
